home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- #
- # myTask.c
- #
- # To be compiled and linked together with "osmain.c.o",
- # and downloaded to a MCP card.
- #
- # The "ClientAppli" application will find "myTask" on a MCP card,
- # and have the messages sent to it echoed.
- #
- # Components:
- # osmain.c
- # myTask.c
- #
- ------------------------------------------------------------------------------*/
-
- #define DUMMYCODE 900
-
-
- // definitions from "os.h":
-
- typedef long tid_type;
-
- struct mMessage
- {
- struct mMessage *mNext;
- long mId;
- short mCode;
- short mStatus;
- unsigned short mPriority;
- tid_type mFrom;
- tid_type mTo;
- unsigned long mSData [3];
- unsigned long mOData [3];
- long mDataSize; // Size of data buffer in bytes. set to negative
- // size of buffer if buffer is shared
- // between tasks. eg. Buffer cannot be copied
- char *mDataPtr;
- };
-
- typedef struct mMessage mMessage;
-
- #define OS_MATCH_ALL 0 // on receive match anything
- #define OS_NO_TIMEOUT 0 // receive waits forever for message
-
- // some #define's from "managers.h":
-
- #define OS_UNKNOWN_MESSAGE (1<<8) // unrecognized message code
- #define Machine_Visible 0 // Register_task Machine visible flag
-
-
- void myTask();
- extern char Register_Task(char *, char *, short);
- extern mMessage *Receive(unsigned long, tid_type, unsigned short, long, ...);
- extern void FreeMsg();
- extern void SwapTID(mMessage *);
- extern void Send(mMessage *);
-
- pascal void illegal () extern 0x4afc;
-
- static char my_object_name [] = "myTaskName";
- static char my_type_name [] = "myTaskType";
-
- void myTask()
- // all it does at this point is to register with the Name Manager
- // (in order to be recognized by possible clients looking for it)
- // and then just send back the messages it receives
-
- {
- mMessage *m;
-
- if (!Register_Task (my_object_name, my_type_name, Machine_Visible))
- illegal (); // go debugging: something mysterious happens
-
- while(1) // forever !
- {
- m = Receive(OS_MATCH_ALL, OS_MATCH_ALL, OS_MATCH_ALL, OS_NO_TIMEOUT);
- if (m) {
- if (m->mStatus != 0) { // what happens? Should investigate!
- FreeMsg(m); // I don't know: better get rid of it
- }
- else {
- switch (m->mCode) {
- case DUMMYCODE:
- // is there something to do with this message ?
- break;
-
- // handle here all the message codes you specified in your design !
-
- default:
- m->mCode |= 0x8000; // unrecognized message code;
- m->mStatus = OS_UNKNOWN_MESSAGE;
- // defined in "managers.h"
- break;
- } // switch
-
- // send message back
- SwapTID(m); // swap mFrom <-> mTo fields
- m->mCode++; // by convention
- Send(m);
-
- } // message status was OK
-
- } // there was a message
-
- } // while (1)
-
- } // end myTask()
-